package com.example.duomeitijuhe.ui;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import com.example.duomeitijuhe.R;
import com.example.duomeitijuhe.bean.GetInternetDataBean;
import com.example.duomeitijuhe.db.OperateDatabase;
import com.example.duomeitijuhe.others.ActivityCollector;
import java.util.Timer;
import java.util.TimerTask;

public class StartActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    private Timer timer;
    private TimerTask task;
    private Intent intent;
    private GetInternetDataBean getInternetDataBean;

    OperateDatabase operateDatabase;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityCollector.addActivity(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        initDatas();
        intent = new Intent();

    }
    public void initDatas(){
        getInternetDataBean = new GetInternetDataBean();
        getInternetDataBean.setUserId("4");
        getInternetDataBean.setWeiboId("5");
        getInternetDataBean.setSenderId("1");
        getInternetDataBean.setSenderName("糗事大百科");
        getInternetDataBean.setSenderIconUrl("http://tp3.sinaimg.cn/1720084970/50/40063731097/1");
        getInternetDataBean.setSendTime("Wed Oct 15 22:42:14 +0800 2014");
        getInternetDataBean.setContent("路口的卷发了空间发呆爱上咖啡加拉克的风景阿迪发了快放假啊水电费阿里对方阿萨德卡发放将塑料袋口附近爱上大叔了短发三季度浪费阿道夫卡死了");
        getInternetDataBean.setIsRetransmit(1);
        getInternetDataBean.setContentPictureUrl("pic_urls:[{\"thumbnail_pic\":\"http://ww2.sinaimg.cn/thumbnail/40be9ba7gw1elc5ij0g5oj20go0m7t9y.jpg\"}]");
        getInternetDataBean.setOriginalSenderIconUrl("http://tp2.sinaimg.cn/2241191261/50/22842000667/1");
        getInternetDataBean.setOriginalSenderName("又逗比了");
        getInternetDataBean.setSenderId("2");
        getInternetDataBean.setOriginalContent("减肥啦速度解决上课都发了啥就垃圾堆里金额为IgG啊女女奥斯卡了上奥斯卡静安寺打了舒服按时交电费拉丝机发生了放辣椒死掉了风景啊飞机发生了地激发了上法犯法速度放假");
        getInternetDataBean.setOriginalPictureUrl("\"pic_urls\":[{\"thumbnail_pic\":\"http://ww4.sinaimg.cn/thumbnail/61e8a1fdgw1elc7b1x869g204v048gmn.gif\"}]");

        operateDatabase = new OperateDatabase(StartActivity.this,1);
        Cursor cursor = operateDatabase.queryDb("InternetData");
        boolean b = false;
        if (cursor.moveToFirst()){
            do {
                String weibo = cursor.getString(cursor.getColumnIndex("weiboId"));
                if (weibo.equals(getInternetDataBean.getWeiboId())){
                    b=true;
                }
            }while (cursor.moveToNext());
        }
        if (b == false){
            operateDatabase.insertDbInternetData(getInternetDataBean);
        }
        cursor.close();
        operateDatabase.closeDb();
    }
    @Override
    public void finish() {
        super.finish();
        Log.e("finish","finish");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e("destroy","destroy");
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

    }


    @Override
    protected void onStart() {
        super.onStart();
        timer = new Timer();
        task = new TimerTask() {
            @Override
            public void run() {
                Log.i("StartActivity: ","延迟3秒");
                intent.setClass(StartActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();

            }
        };
        timer.schedule(task, 1000 * 3);


    }

}

